<?php

header("Content-type: text/html; charset=utf-8");

$con = mysql_connect("localhost","root","");

if (!$con) {
  die('Could not connect: ' . mysql_error());
}
mysql_select_db("my-english", $con);
mysql_query('SET NAMES utf8');

mysql_query("INSERT INTO en_words VALUES (null, '".$_POST['word']."', null)");
$relation = mysql_insert_id();
$trans = preg_split("/[\n\r]/", $_POST['tran']);
$wordtype = "null";
for ($i=0; $i<count($trans); $i++) {
	$num = preg_match_all("/.*(noun|adjective|adverb|verb|interjection|preposition)/", $trans[$i], $matches);
	if ($num == 0) {
		mysql_query("INSERT INTO ru_words VALUES (null, '" .trim($trans[$i]). "', $relation, '" .$wordtype. "')");
	} else {
		$wordtype = $matches[1][0];
	}
}

?> 